package com.lt.flashcard.model.entity;

import java.util.Date;

import org.bson.types.ObjectId;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;

/**
 * The promotion that apply for a flashcardset and valid in a range of date
 * @author ocsen
 *
 */
@Entity(value="promotion", noClassnameStored=true)
public class Promotion {

	@Id
	private ObjectId id;
	
	private Date created = new Date();
	
	private Date validFrom = null;
	
	private Date validTo = null;
	
	private int status = STATUS_VALID;
	public static final int STATUS_VALID = 1;
	public static final int STATUS_INVALID = 0;
	
	private String note = "";
	/**
	 * The type that this promotion will provide
	 */
	private int type = TYPE_ADDBLANKCARD;
	public static final int TYPE_ADDBLANKCARD = 0;
	public static final int TYPE_ADDYELLOWCOIN = 1;
	public static final int TYPE_ADDBLUECOIN = 2;
	public static final int TYPE_GAINMEDAL = 3;
	/**
	 * The object that this promotion will affect
	 */
	private int targetType = TARGETTYPE_FLASHCARDSET;
	public static final int TARGETTYPE_FLASHCARDSET = 0;
	public static final int TARGETTYPE_USER = 1;
	public static final int TARGETTYPE_CODE = 2;
	/**
	 * The condition to gain this promotion
	 */
	private int conditiontype = 0; //Condition to gain this promotion
	public static final int CONDITIONTYPE_FIRSTLOGIN = 1;
	public static final int CONDITIONTYPE_LOGINAT = 2; //Login on exact day
	public static final int CONDITIONTYPE_VISIT = 3; //Visit a target page
	public static final int CONDITIONTYPE_BUYITEM = 4; //Buy an item to gain promotion
	public static final int CONDITIONTYPE_LEARNED = 5; //Learn a number of flashcards
	public static final int CONDITIONTYPE_MAKEFRIEND = 6; //Make friend with a number of user
	public static final int CONDITIONTYPE_KNOWWORDS = 7; //The condition for current know words
	public static final int CONDITIONTYPE_KNOWWORDS_L0 = 8; //The condition for current know words at level 0
	public static final int CONDITIONTYPE_KNOWWORDS_L1 = 9; //The condition for current know words at level 1
	public static final int CONDITIONTYPE_KNOWWORDS_L7 = 10; //The condition for current know words at level 7
	public static final int CONDITIONTYPE_TESTCONTINUOUS = 11; //Take a number of continuous test
	public static final int CONDITIONTYPE_ACTIVECODE = 12; //When active a code successfully
	/**
	 * The id of the target, maybe flashcardset or user or... For ex, buy an item
	 */
	private Long targetId; //target id as Long number
	private String targetIdStr; //target id as String
	private String medalid; //The id of medal to gain
	private int value = 0; //use for gain coin, flashcardset
	
	private Date condition_date; //The date use for login condition
	private String condition_url;
	private int condition_value = 0; //used for learned, makefriend, knowwords

	public ObjectId getId() {
		return id;
	}

	public void setId(ObjectId id) {
		this.id = id;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Date getValidFrom() {
		return validFrom;
	}

	public void setValidFrom(Date validFrom) {
		this.validFrom = validFrom;
	}

	public Date getValidTo() {
		return validTo;
	}

	public void setValidTo(Date validTo) {
		this.validTo = validTo;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	public int getType() {
		return type;
	}
	
	public String getTypeStr() {
		switch(type) {
		case TYPE_ADDBLANKCARD: return "Add blank card";
		case TYPE_ADDBLUECOIN: return "Add blue coin";
		case TYPE_ADDYELLOWCOIN: return "Add yellow coin";
		case TYPE_GAINMEDAL: return "Gain medal";
		}
		return "Unknow";
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getTargetType() {
		return targetType;
	}
	
	public String getTargetTypeStr() {
		switch(targetType) {
		case TARGETTYPE_FLASHCARDSET: return "FlashcardSet";
		case TARGETTYPE_USER: return "User";
		}
		return "Unknow";
	}

	public void setTargetType(int targetType) {
		this.targetType = targetType;
	}

	public Long getTargetId() {
		return targetId;
	}

	public void setTargetId(Long targetId) {
		this.targetId = targetId;
	}

	public int getConditiontype() {
		return conditiontype;
	}
	
	public String getConditiontypeStr() {
		switch(conditiontype) {
		case CONDITIONTYPE_BUYITEM: return "Buy item";
		case CONDITIONTYPE_FIRSTLOGIN: return "First login";
		case CONDITIONTYPE_KNOWWORDS: return "Know words";
		case CONDITIONTYPE_KNOWWORDS_L0: return "Know words l0";
		case CONDITIONTYPE_KNOWWORDS_L1: return "Know words l1";
		case CONDITIONTYPE_KNOWWORDS_L7: return "Know words l7";
		case CONDITIONTYPE_LEARNED: return "Learned";
		case CONDITIONTYPE_LOGINAT: return "Login at";
		case CONDITIONTYPE_MAKEFRIEND: return "Make friend";
		case CONDITIONTYPE_VISIT: return "Visit";
		case CONDITIONTYPE_TESTCONTINUOUS: return "Test continuous";
		}
		return "Unknow";
	}

	public void setConditiontype(int conditiontype) {
		this.conditiontype = conditiontype;
	}

	public Date getCondition_date() {
		return condition_date;
	}

	public void setCondition_date(Date condition_date) {
		this.condition_date = condition_date;
	}

	public String getCondition_url() {
		return condition_url;
	}

	public void setCondition_url(String condition_url) {
		this.condition_url = condition_url;
	}

	public int getCondition_value() {
		return condition_value;
	}

	public void setCondition_value(int condition_value) {
		this.condition_value = condition_value;
	}

	public String getMedalid() {
		return medalid;
	}

	public void setMedalid(String medalid) {
		this.medalid = medalid;
	}

	public int getValue() {
		return value;
	}

	public void setValue(int value) {
		this.value = value;
	}

	/**
	 * @return the targetIdStr
	 */
	public String getTargetIdStr() {
		return targetIdStr;
	}

	/**
	 * @param targetIdStr the targetIdStr to set
	 */
	public void setTargetIdStr(String targetIdStr) {
		this.targetIdStr = targetIdStr;
	}
}
